from django.db import models
import datetime
from django.utils.timezone import utc
# Create your models here.
class Cluster(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=32)
    describe = models.CharField(max_length=32)
    config=models.CharField(max_length=20,default=None)
    lastsvcip=models.GenericIPAddressField(max_length=16,default="1.1.1.1")
    def __str__(self):
        return self.name

class Namespace(models.Model):
    #id是django默认帮你创建，然后默认是主键，自增长
    #列名 ,字符串类型，指定字符串的长度为32
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=32)
    describe= models.CharField(max_length=32)
    nas = models.CharField(max_length=128,default="1.1.1.1")
    nas_catalogue = models.CharField(max_length=128,default="1.1.1.1")
    cluster=models.ForeignKey("Cluster",to_field="id",default=1,on_delete=models.CASCADE,related_name="group_cluser")
    def __str__(self):
        return self.name

class Web(models.Model):
    #id是django默认帮你创建，然后默认是主键，自增长
    #列名 ,字符串类型，指定字符串的长度为32
    id = models.AutoField(primary_key=True)
    project=models.CharField(max_length=32)
    name = models.CharField(max_length=32)
    domain=models.CharField(max_length=64,unique=True)
    mysql_host = models.CharField(max_length=128)
    namespace = models.ForeignKey("Namespace", to_field="id", default=1, on_delete=models.CASCADE,related_name="group_namespace")
    php_url=models.CharField(max_length=64,default="/")
    php_status=models.IntegerField(default=1) #0异常 1正常
    status=models.IntegerField(default=1) #0异常 1正常
    def __str__(self):
        return self.name

class Dsjob(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=32,unique=True)
    image=models.CharField(max_length=128)
    plan = models.CharField(max_length=128,default="*/1 * * * *")
    cluster=models.CharField(max_length=64)
    status=models.IntegerField(default=1) #0异常 1正常
    create_time=models.DateTimeField('创建时间', default=datetime.datetime.now().replace(tzinfo=utc))
    def __str__(self):
        return self.name

class Host(models.Model):
    id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=32)
    os=models.CharField(max_length=32)
    status=models.CharField(max_length=16)
    desc= models.CharField(max_length=32)
    outip=models.GenericIPAddressField()
    inip=models.GenericIPAddressField(unique=True)
    cpu=models.IntegerField()
    mem=models.IntegerField()
    create_time=models.DateTimeField('创建时间', default=datetime.datetime.now().replace(tzinfo=utc))
    expiry_time=models.DateTimeField('创建时间', default=datetime.datetime.now().replace(tzinfo=utc))
    def __str__(self):
        return self.name
